<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
 */

function tep_create_sort_heading_new($sortby, $colnum, $heading) {
    global $PHP_SELF;

    $sort_prefix = '';
    $sort_suffix = '';

    if ($sortby) {
        $sort_prefix = '<a href="javascript:void(0);" onclick="change_sort(' . $colnum . ')" title="' . tep_output_string(TEXT_SORT_PRODUCTS . TEXT_BY . $heading) . '" class="productListing-heading">';
        $sort_suffix = '</a>';
    }

    return $sort_prefix . $heading . $sort_suffix;
}

//mvigil514 bof Compare Products
$cPathCompare = $cPath;
$pageCompare = $_GET['page'];
$sortCompare = $_GET['sort'];
$mfrCompare = $_GET['manufacturers_id'];
$filterCompare = $_GET['filter_id'];
//mvigil514 eof Compare Products

  //--------------------------------------------------------------------------------------------------	
 
 //-----------------Modify by NamHai 12/07/2012-----------------------  
//$listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id'); // constant "MAX_DISPLAY_SEARCH_RESULTS" set default ==20 in table "configuration" when install OSC  
$max_row_per_page = 2;
$listing_split = new splitPageResults($listing_sql, $max_row_per_page, 'p.products_id'); // here set "$max_rows==2" per page (review 'class/split_page_results.php')
//-----------------End by NamHai 12/07/2012--------------------------- 

//mvigil514 bof Compare Products
$urlString = $_SERVER['QUERY_STRING'];

$compare_link = tep_href_link(FILENAME_COMPARE, ($cPathCompare ? 'cPath=' . $cPathCompare . '&page=' . $pageCompare . '&sort=' . $sortCompare . '&filter_id=' . $filterCompare : ''));
//echo tep_draw_form('compare', tep_href_link(FILENAME_COMPARE, ($cPathCompare ? 'cPath=' . $cPathCompare . '&page=' . $pageCompare . '&sort=' . $sortCompare . '&filter_id=' . $filterCompare : '')), 'post', 'onsubmit="return validateButton();"', '', true);
//mvigil514 eof Compare Products

$data_ok = ($listing_split->number_of_rows > 0);
if ((PRODUCT_LIST_DESCRIPTION ) && $data_ok) {
    $listing_query = tep_db_query($listing_split->sql_query);
    while ($products = tep_db_fetch_array($listing_query))
        $id_array[] = $products['products_id'];

    $pid_string = implode(',', array_unique($id_array));
    $product_query = tep_db_query($q = "select products_id, products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id in (" . $pid_string . ") and language_id = '" . (int) $languages_id . "'");
    while ($products = tep_db_fetch_array($product_query)) {
        $t_desc[$products['products_id']] = substr(strip_tags($products['products_description']), 0, PRODUCT_LIST_DESCRIPTION_MAX_LENGTH);
    }
}

function product_description($product_id, $link) {
    global $t_desc;
    if (PRODUCT_LIST_DESCRIPTION) {
        return '<br /><span class="productDesc">' . $t_desc[$product_id] . $link . '<strong>...' . MORE . '</strong></a></span>';
    } else {
        return false;
    }
}
?>

<div class="contentText">

    <?php
    if (($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') )) {
        
        //----------------------Modify and added by NamHai 12/07/2012-----------------------
        ?>
        <div>
            <!--<span style="float: right;"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links_filter(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span>
            <span><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS_1); ?></span>-->
            <span style="float: right;"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS_1); ?></span>
        </div>
        <br />
        <br />
        <?php

        //--------------------------End by NamHai 12/07/2012----------------------
    }

    $prod_list_contents = '<div class="ui-widget infoBoxContainer">' .
            '  <div class="ui-widget-header ui-corner-top infoBoxHeading">' .
            '    <table border="0" width="100%" cellspacing="0" cellpadding="2" class="productListingHeader">' .
            '      <tr>';

    for ($col = 0, $n = sizeof($column_list); $col < $n; $col++) {
        $lc_align = '';

        switch ($column_list[$col]) {
            case 'PRODUCT_LIST_MODEL':
                $lc_text = TABLE_HEADING_MODEL;
                $lc_align = '';
                break;
            case 'PRODUCT_LIST_NAME':
                $lc_text = TABLE_HEADING_PRODUCTS;
                $lc_align = '';
                break;
            case 'PRODUCT_LIST_MANUFACTURER':
                $lc_text = TABLE_HEADING_MANUFACTURER;
                $lc_align = '';
                break;
            case 'PRODUCT_LIST_PRICE':
                $lc_text = TABLE_HEADING_PRICE;
                $lc_align = 'right';
                break;
            case 'PRODUCT_LIST_QUANTITY':
                $lc_text = TABLE_HEADING_QUANTITY;
                $lc_align = 'right';
                break;
            case 'PRODUCT_LIST_WEIGHT':
                $lc_text = TABLE_HEADING_WEIGHT;
                $lc_align = 'right';
                break;
            case 'PRODUCT_LIST_IMAGE':
                $lc_text = TABLE_HEADING_IMAGE;
                $lc_align = 'center';
                break;
            case 'PRODUCT_LIST_BUY_NOW':
                //$lc_text = TABLE_HEADING_BUY_NOW;
            	$lc_text = IMAGE_BUTTON_OPTION; //-----------Added by NamHai 12/07/2012------------
                $lc_align = 'center';
                break;
        }

        if (($column_list[$col] != 'PRODUCT_LIST_BUY_NOW') && ($column_list[$col] != 'PRODUCT_LIST_IMAGE')) {
            $lc_text = tep_create_sort_heading_new($HTTP_GET_VARS['sort'], $col + 1, $lc_text);
        }

        $prod_list_contents .= '        <td' . (tep_not_null($lc_align) ? ' align="' . $lc_align . '"' : '') . '>' . $lc_text . '</td>';
    }

    $prod_list_contents .= '      </tr>' .
            '    </table>' .
            '  </div>';

    if ($listing_split->number_of_rows > 0) {
        $products_found = true;
        $rows = 0;
        $listing_query = tep_db_query($listing_split->sql_query);
        $prodCount = mysql_num_rows($listing_query);

        $prod_list_contents .= '  <div class="ui-widget-content ui-corner-bottom productListTable">' .
               '    <table border="0" width="100%" cellspacing="0" cellpadding="2" class="productListingData">';

        while ($listing = tep_db_fetch_array($listing_query)) {
            $rows++;
            if ($rows % 2 == 0) {
                $prod_list_contents .= '      <tr class="alt">';
            } else {
                $prod_list_contents .= '      <tr>';
            }


            for ($col = 0, $n = sizeof($column_list); $col < $n; $col++) {
                switch ($column_list[$col]) {
                    case 'PRODUCT_LIST_MODEL':
                        $prod_list_contents .= '        <td>' . $listing['products_model'] . '</td>';
                        break;
                    case 'PRODUCT_LIST_NAME':
                        $man_id = (tep_not_null($_GET['manufacturers_id']) ? $_GET['manufacturers_id'] : '');
                        $link = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $listing['products_id'] . ($man_id ? '&manufacturers_id=' . $man_id : ($cPath && $cat_path ? '&cPath=' . $cPath : ''))) . '"' . ($man_id || ($cat_path && $cat_path) ? ' rel="nofollow"' : '') . '>';


                        if ($prodCount > 1) {
                            $prod_list_contents .= '        <td width="250">' . $link . $listing['products_name'] . '</a>' . product_description($listing['products_id'], $link) . '<br /><span><input type="checkbox" name="checkgroup[]" class="compare" id="checkgroup" value="' . $listing['products_id'] . '" onClick="javascript:updateCompare();"/><a href="' . $compare_link . '" onClick="return validateButton();">' . TEXT_COMPARE_CHECKBOX . '</a></span></td>';
                        } else {
                            $prod_list_contents .= '        <td width="250">' . $link . $listing['products_name'] . '</a>' . product_description($listing['products_id'], $link) . '</td>';
                        }

                        break;
                    case 'PRODUCT_LIST_MANUFACTURER':
                        $prod_list_contents .= '        <td><a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' . $listing['manufacturers_name'] . '</a></td>';
                        break;
                    case 'PRODUCT_LIST_PRICE':
 
 if (tep_not_null($listing['specials_new_products_price'])) {
              $prod_list_contents .= '        <td align="right width="100"><del>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</del>&nbsp;&nbsp;<span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></td>';
            } else {
              $prod_list_contents .= '        <td align="right" width="100"><span class="price_red">' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></td>'; }
			  /*					
                        if (tep_not_null($listing['specials_new_products_price'])) {
                            $prod_list_contents .= '        <td align="right"><del>' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</del>&nbsp;&nbsp;<span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></td>';
                        } else {
                            $prod_list_contents .= '        <td align="right">' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</td>';
                        }*/
                        break;
                    case 'PRODUCT_LIST_QUANTITY':
                        $prod_list_contents .= '        <td align="right">' . $listing['products_quantity'] . '</td>';
                        break;
                    case 'PRODUCT_LIST_WEIGHT':
                        $prod_list_contents .= '        <td align="right">' . $listing['products_weight'] . '</td>';
                        break;
                    case 'PRODUCT_LIST_IMAGE': //DIR_WS_IMAGES .
                        if (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
                            $prod_list_contents .= '        <td align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image( $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>';
                        } else { //DIR_WS_IMAGES .
                            /*$prod_list_contents .= '        <td align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image( $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>';*/
							
			$prod_list_contents .= '        <td><div class="product_img"><p><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image( $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></p>';			 
				/*
		   $prod_list_contents .= '<div class="star_rating" id="'.$listing['products_rating'].'_1"></div>';
				
			$prod_list_contents .= '<span class="reviews"> ('.$listing['products_review_count'].')</span>';
			$prod_list_contents .= '</div>';*/							
                        }
                        break;
                    case 'PRODUCT_LIST_BUY_NOW':
				/*	 $l=tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']);//add by donghp
					 
                        $prod_list_contents .= '        <td align="center">' . tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart',$l) . '</td>';
                        break;
*/
 $prod_list_contents .= '        <td align="center">';
 
 if ($listing['products_price'] > 0 ) 
 {
 $prod_list_contents .= '<a href = "'.tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id'])  . '"> '.IMAGE_BUTTON_BUY_NOW.'</a> | ';
  
   $prod_list_contents .= '<a href = "'.tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=add_cart&products_id=' . $listing['products_id'])  . '"> '.IMAGE_BUTTON_IN_CART.'</a>';
}
 
   $prod_list_contents .= tep_draw_hidden_field('products_id', $product_info['products_id']);
 
   $prod_list_contents .='</td>';
   						
                }
            }

            $prod_list_contents .= '      </tr>';
        }

        $prod_list_contents .= '    </table>' .
                '  </div>' .
                '</div>';

        echo $prod_list_contents;
    } else {
        $products_found = false;
        ?>

        <p><?php echo TEXT_NO_PRODUCTS; ?></p>

        <?php
    }

    if (($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3'))) {
        
        //--------------------Modify and added by NamHai12/07/2012-----------------
    		$max_number_pages_display = 4;
    	?>
        <br />
        <div>
            <span><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS_1); ?></span>
            <span style="float: right;"><?php echo TEXT_RESULT_PAGE . ' ' .$listing_split->display_pages_result($max_row_per_page, $max_number_pages_display); ?></span>
            
            <!--<span style="float: right;"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links_filter(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span>-->
            <center><span><?php echo $listing_split->display_links_filter($max_number_pages_display, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span></center>
        </div>
        <?php
        //--------------------------End by NamHai 12/07/2012---------------------------
    }
    ?>

</div>

<?php
//mvigil514 eof Compare Products
?>
